package ch08_Swing高级组件.combo;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

public class CountryComboBoxCellRenderer implements ListCellRenderer{

	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
			boolean cellHasFocus) {
		JPanel item = (JPanel) value;
		JLabel countryLab = (JLabel) item.getComponent(1);
		JLabel descLab = (JLabel) item.getComponent(2);
		descLab.setForeground(new Color(0x888888));
		
		if(!isSelected) {
			if(index%2==0) {
				item.setBackground(new Color(0xFFFFFF));
			}else {
				item.setBackground(new Color(0xD0D0D0));
			}
			countryLab.setForeground(Color.BLACK);
		}else {
			item.setBackground(Color.DARK_GRAY);
			countryLab.setForeground(Color.WHITE);
		}
		return item;
	}
	
}
